home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: Compiler unable to comprehend template for "<<" operator. What's wrong???
- Message-ID: <marnoldDo3BBI.5Hw@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <4hto1l$bvl@newshost.lanl.gov>
- Date: Mon, 11 Mar 1996 06:28:30 GMT
- Sender: marnold@netcom8.netcom.com
-
- staley@canary.lanl.gov (Martin Staley) writes:
-
-
- >Consider the following code:
-
- > #include <iostream.h>
-
- > template<class Type>
- > class vector {
- > Type *v;
- > int size;
- > friend ostream &operator<<(ostream &, vector<Type> &);
- > };
-
- > template<class Type>
- > ostream &operator<<(ostream &ostr, vector<Type> &vec) {
- > }
-
- > main() {
- > vector<float> v;
- > cout << v;
- > }
-
- >This is an extremely simplified version of some stuff I'm writing. But
- >it will not compile. Both g++ (for the Suns) and Sun c++ give me the
- >following error:
-
- > ld: Undefined symbol
- > ___ls__FR7ostreamRt6vector1Zf
-
- >Apparently the compiler doesn't know how to use the template for
- >operator<< to instantiate the << operator for a vector<float>. WHAT'S
- >WRONG HERE??? I've tried several minor variations to the above code,
- [snip]
- >Again, the compiler seems unable to build the necessary operator<<.
- >Things work fine if I write operator<< specifically for floats:
- [snip]
- >Can anybody tell me what, if anything, that I am doing wrong above?
-
- Nothing.
-
- Apparently, the compiler you are using doesn't work. Your code compiles
- and runs *as-is* (I just cut and pasted it) without errors under Borland
- C++.
-
- As a work-around, I guess you *will* have to explicity write each
- variation of your friend operator<<() function until your compiler vendor
- is inclined to properly support the langauge. C'est la vie. :-(
-
- Report your code to the vendor as a clear demonstration of a language
- support bug.
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-
-